package com.youbug.system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youbug.system.entity.Carousel;
import com.youbug.system.service.ICarouselService;
import com.youbug.system.vo.CarouselVo;
import com.youbug.common.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 官网轮播图存储表 前端控制器
 * </p>
 *
 * @author youbug
 * @since 2023-04-13
 */
@RestController
@RequestMapping("/carousel")
public class CarouselController {

    @Autowired
    private ICarouselService carouselService;

    @PostMapping("/getCarousels")
    public R<IPage<Carousel>> getAnsmts(@RequestBody CarouselVo vo){

        IPage<Carousel> page = carouselService.getCarouselPage(vo);

        return R.ok(page);
    }

    @GetMapping("/getCarousel/{id}")
    public R<Carousel> getAnsmt(@PathVariable String id){

        Carousel carousel = carouselService.getById(id);

        return R.ok(carousel);
    }

    @PostMapping("/add")
    public R<Boolean> add(@RequestBody Carousel carousel){

        boolean save = carouselService.save(carousel);

        return  R.ok(save);
    }

    @GetMapping("/delete/{id}")
    public R<Boolean> delete(@PathVariable String id){

        boolean remove = carouselService.removeById(id);

        return  R.ok(remove);
    }

    @PostMapping("/update")
    public R<Boolean> update(@RequestBody Carousel carousel){

        boolean save = carouselService.updateById(carousel);

        return  R.ok(save);
    }
}

